<template>
	<view class="content" @touchmove.stop.prevent>
		<view class="top_search-box">
			<view class="top_search">
				<view class="s-i">
					<input class="s-input" type="text" @confirm="searchTap" v-model="keywords" placeholder="商品名称" />
					<view class="s-btn" @click="searchTap">搜索</view>
				</view>
				<view class="m-x" @click="$navTo('/pages/groupbuy/businessQuota?type=1')">
					米分明细
				</view>
			</view>
		</view>

		<view class="l-box">
			<scroll-view scroll-y class="left-aside" @touchmove.stop.prevent>
				<view v-for="(item,index) in tabList" :key="item.id">
					<view v-if="index!=1" class="f-item b-b" :class="{active: item.id === cateId}"
						@click="tabtap(item,index)">
						{{item.name}}
					</view>
				</view>
			</scroll-view>
			<scroll-view class="right-aside" scroll-y lower-threshold="400" @touchmove.stop.prevent @scrolltolower="getList">
				<view class="s-list">
					<view class="t-list">
						<view class="goods_list" v-for="item,i in list" :key="item.id" @click="buyShop(item)">
							<view class="g_left">
								<image :src="item.thumb"></image>
							</view>
							<view class="g_right">
								<view>
									<view class="tit">
										{{item.title}}
									</view>
								</view>
								<view class="price_box">
									<view style="display: flex;align-items: center;">
										<text class="now_price">
											{{Number(item.agentprice)}} <text
												style="font-size: 24rpx;margin-left: 12rpx;">米分</text>
										</text>
									</view>

									<view class="btn">
										<text class="go_buy">抢购</text>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="empty_loading2">
						<image v-if="isloading" src="/static/business/loading.gif"></image>
						<view v-if="isempty">———— <text>没有更多了</text> ————</view>
					</view>
					<view style="height: 200rpx;"></view>
				</view>
			</scroll-view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				keywords: '',
				miFenShopId: '', //一级分类ID
				cateId: 0, //二级分类ID
				pcate: '',
				page: 0,
				list: [],
				isloading: false,
				isempty: false,
				tabList: [], //导航列表
			}
		},
		onLoad() {
			this.getMiFenId()
		},
		methods: {
			init() {
				this.page = 0
				this.list = []
				this.isempty = false
				this.isloading = false
				this.getList();
			},
			// 购买商品
			buyShop(e) {
				this.$navTo(`/pages/product/product?miFenShopId=${this.miFenShopId}&id=${e.id}`)
			},
			// 获取一级分类id
			async getMiFenId() {
				const res = await this.$axios('Group/getCreditInfoLevel1', "POST", 'pintuan')
				if (res.data.code == 200) {
					this.miFenShopId = res.data.data.goodsCardCateId || '';
					this.pcate = this.miFenShopId
					this.init()
				}
			},
			//二级分类点击
			tabtap(item, index) {
				if (this.cateId == item.id) {
					return
				}
				this.pcate = index != 0 ? '' : this.miFenShopId
				this.cateId = item.id;
				this.init();
			},
			// 获取二级分类商品
			getList() {
				this.isloading = true;
				this.isempty = false;
				this.page++;
				const pcate = this.pcate,
					cateId = this.cateId
				this.$axios('Lists/index', 'POST', 'shop', {
					page: this.page,
					keywords: this.keywords,
					...(pcate ? {} : {
						ccate: cateId
					}),
					...(pcate ? {
						pcate
					} : {})
				}).then(res => {
					this.isloading = false;
					if (cateId != this.cateId || pcate != this.pcate) {
						return
					}
					if (res.data.code == 200) {
						if (this.page == 1) {
							this.tabList = res.data.data.category || this.tabList
						}
						let data = res.data.data.goods || [];
						this.list = [...this.list, ...data];
						this.isempty = data.length <= 20;
					}
				})
			},
			// 点击搜索
			searchTap() {
				this.init()
			}
		}
	}
</script>

<style scoped lang='scss'>
	page,
	.content {
		height: 100%;
		background-color: #fff;
	}

	.content {
		.top_search-box {
			height: calc(var(--status-bar-height) + var(--window-top) + 50rpx + 76rpx);
			background: linear-gradient(180deg, #E9C7FF 0%, #FFFFFF 100%);

			.top_search {
				position: fixed;
				top: 0;
				width: 100%;
				/* #ifdef MP*/
				width: 550rpx;
				/* #endif */
				background: linear-gradient(180deg, #E9C7FF 0%, #FFFFFF 100%);
				padding-top: calc(var(--status-bar-height) + var(--window-top) + 50rpx);
				display: flex;
				align-items: center;
				padding-left: 20rpx;
				.s-i {
					flex: 1;
					border-radius: 142rpx;
					border: 2rpx solid #9A1FE8;
					height: 72rpx;
					position: relative;
					padding-right: 86rpx;

					.s-input {
						height: 72rpx;
						width: 100%;
						padding: 0 12rpx 0 20rpx;
					}

					.s-btn {
						position: absolute;
						right: 0;
						top: 0rpx;
						height: 70rpx;
						line-height: 70rpx;
						color: #9A1FE8;
						width: 86rpx;
						border-left: 2rpx #8813E2 dotted;
						text-align: center;
					}
				}

				.m-x {
					font-weight: bold;
					padding-left: 10rpx;
					color: #9A1FE8;
				}
			}
		}

		.l-box {
			padding-top: 32rpx;

			.left-aside {
				position: fixed;
				flex-shrink: 0;
				width: 168rpx;
				height: calc(100vh - 32rpx - var(--status-bar-height) - var(--window-top) - 50rpx - 76rpx);
				background-color: #f8f8f8;
			}

			.right-aside {
				position: fixed;
				left: 168rpx;
				width: calc(100% - 168rpx);
				height: calc(100vh - 32rpx - var(--status-bar-height) - var(--window-top) - 50rpx - 76rpx);
				background: #fff;
			}

		}
	}



	.f-item {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 120rpx;
		font-size: 28rpx;
		color: $font-color-base;
		position: relative;
		padding: 0 4rpx;
		text-align: center;

		&.active {
			color: #13001E;
			font-weight: 600;
			background: #fff;

			&:before {
				content: '';
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				height: 100rpx;
				width: 12rpx;
				background-color: $base-color;
				border-radius: 0 40rpx 40rpx 0;
				opacity: .8;
			}
		}
	}


	.s-item {
		display: flex;
		align-items: center;
		height: 70upx;
		padding-top: 8upx;
		font-size: 28upx;
		color: $font-color-dark;
	}

	.t-list {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		background: #fff;
		padding: 0 20rpx;

		.goods_list {
			width: 100%;
			display: flex;
			background-color: #FFFFFF;
			padding: 32rpx 0 32rpx;
			box-sizing: border-box;
			/* margin-bottom: 20rpx; */
			border-bottom: 0.4rpx solid #CCCACD;

			.g_left {
				width: 160rpx;
				height: 160rpx;
				position: relative;
				margin-right: 20rpx;
				border-radius: 8rpx;
				box-shadow: 0 0 4rpx 4rpx rgba(#999, 0.1);

				image {
					width: 100%;
					height: 100%;
					border-radius: 8rpx;
				}
			}

			.g_right {
				height: 160rpx;
				width: calc(100% - 200rpx);
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.sku {
					font-size: 20rpx;
					color: #999999;
					margin: 10rpx 0;
				}

				.tit {
					font-size: 25rpx;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.price_box {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.btn {
						background: linear-gradient(90deg, #B62BF0 0%, #8813E2 100%);
						display: flex;
						justify-content: center;
						align-items: center;
						width: 112rpx;
						height: 42rpx;
						border-radius: 28rpx;

						.go_buy {
							color: #FFFFFF;
							font-size: 23rpx;
							font-weight: bold;
						}
					}

					.now_price {
						color: #9A1FE8;
						font-size: 36rpx;
					}

					.orgin_price {
						color: #999999;
						font-size: 24rpx;
						margin-left: 10rpx;
						position: relative;

						.line {
							width: 100%;
							height: 2rpx;
							background-color: #999999;
							position: absolute;
							top: 50%;
						}
					}
				}

				.box_border {
					display: flex;
					margin-top: 5rpx;
					height: 36rpx;
					background: linear-gradient(90deg, #F6E9FD 100%, #FFFFFF 100%);
					align-items: center;
					padding: 0 15rpx;

					image {
						width: 74rpx;
						height: 20rpx;
						z-index: 9;
					}

					.status_box {
						width: 100%;
						height: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.u-percentage-slot {
							padding: 1px 5px;
							background-color: #fff;
							color: #9A1FE8;
							border-radius: 100px;
							font-size: 10px;
							padding: 0 20rpx;
							font-weight: 800;
						}

						.limit {
							width: 100%;
							color: #9A1FE8;
							font-size: 20rpx;
							font-weight: normal;
							margin-left: 10rpx;
						}

					}


				}
			}

		}

		.goods_list:first-child {
			padding-top: 0;
		}
	}

	.empty_loading2 {
		display: block;
		margin: 0 auto;
	}
</style>